﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

using LowLevelGraphics;

namespace ImageRecognition2.Action
{
    /// <summary>
    /// Action Save: Used to save a pic
    /// </summary>
    public class ActionSave : AbstractCommand
    {
        /// <summary>
        /// Default constructor
        /// </summary>
        public ActionSave()
        {
        }

        /// <summary>
        /// Used to clone this instance
        /// </summary>
        /// <param name="_actionSave"></param>
        internal ActionSave(ActionSave _actionSave)
        {
        }

        /// <summary>
        /// Runs this instance
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void Run(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            if (saveFileDialog.ShowDialog() != DialogResult.OK) return;

            Bitmap bitmap = (Bitmap)MainFormSingleton.ActivePictureBox.BackgroundImage;

            UnsafeBitmap b = bitmap;
            b.Save(saveFileDialog.FileName);
            b.UnlockImage();
        }

        /// <summary>
        /// Clones this instance
        /// </summary>
        /// <returns></returns>
        public override object Clone()
        {
            return new ActionSave(this);
        }
    }
}
